<template>
  <div class="user-management-container">
    <vab-query-form>
      <vab-query-form-left-panel :span="12">
        <el-select v-model="value" clearable placeholder="请选择审核状态">
          <el-option
            v-for="item in options1"
            :key="item.id"
            :label="item.creClasName"
            :value="item.id"
            @click.native="optosall(item)"
          />
        </el-select>

        <el-date-picker
          v-model="PayTime"
          end-placeholder="结束日期"
          range-separator="至"
          start-placeholder="开始日期"
          style="margin-left: 20px"
          type="daterange"
          @change="GetzhifuTime"
        />
      </vab-query-form-left-panel>
      <vab-query-form-right-panel :span="12">
        <el-form :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item>
            <el-input
              v-model.trim="queryForm.keyWord"
              clearable
              placeholder="请输入用户名"
            />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" type="primary" @click="queryData">
              查询
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>
    </vab-query-form>

    <el-table
      v-loading="listLoading"
      border
      :data="list"
      :row-style="rowStyle"
      @selection-change="setSelectRows"
    >
      <el-table-column align="center" show-overflow-tooltip type="selection" />
      <el-table-column
        align="center"
        label="数字id"
        prop="digitalId"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="领队名称"
        prop="leaNickName"
        show-overflow-tooltip
      />

      <el-table-column
        align="center"
        label="姓名"
        prop="leaName"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{ scope.row.leaName }}

          <br />
          <template v-if="scope.row.locked == 0">
            <span style="color: green">未锁定</span>
          </template>
          <template v-if="scope.row.locked == 1">
            <span style="color: red">已锁定</span>
          </template>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="手机号"
        prop="phone"
        show-overflow-tooltip
      />
      <el-table-column align="center" label="实名信息">
        <template slot-scope="scope">
          {{ scope.row.userName }}
          <br />

          <img
            class="el-avatar el-avatar--circle"
            :src="scope.row.headPortrait"
          />
        </template>
      </el-table-column>
      <el-table-column align="center" label="实名认证" show-overflow-tooltip>
        <template slot-scope="scope">
          <template v-if="scope.row.realName == 0">
            <span style="color: red">未审核</span>
          </template>
          <template v-else-if="scope.row.realName == 1">
            <span style="color: gray">审核中</span>
          </template>
          <template v-else-if="scope.row.realName == 2">
            <span style="color: green">审核成功</span>
          </template>
          <template v-else-if="scope.row.realName == 3">
            <span style="color: red">审核未通过</span>
          </template>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="所属协作公司"
        prop="ofEnterprise"
        show-overflow-tooltip
      />
      <el-table-column align="center" label="是否是企业" show-overflow-tooltip>
        <template slot-scope="scope">
          <template v-if="scope.row.authEnterprise == 0">
            <span style="color: red">个人</span>
          </template>
          <template v-else-if="scope.row.authEnterprise == 1">
            <span style="color: gray">企业</span>
          </template>
        </template>
      </el-table-column>
      <el-table-column
        v-if="list.authEnterprise == 1"
        align="center"
        label="营业执照"
      >
        <template slot-scope="scope">
          <img :src="scope.row.enterpriseLicense" />
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="创建时间"
        prop="createTime"
        show-overflow-tooltip
      />
      <el-table-column align="center" label="身份认证" show-overflow-tooltip>
        <template slot-scope="scope">
          <template v-if="scope.row.authLeader == 0">
            <span style="color: red">未认证</span>
          </template>
          <template v-else-if="scope.row.authLeader == 1">
            <span style="color: red">待审核</span>
          </template>
          <template v-if="scope.row.authLeader == 2">
            <span style="color: green">审核通过</span>
          </template>
          <template v-else-if="scope.row.authLeader == 3">
            <span style="color: red">未通过</span>
          </template>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="操作"
        show-overflow-tooltip
        width="220"
      >
        <template #default="{ row }">
          <el-button type="text" @click="handleEdit(row)">编辑</el-button>
          <!-- @click="handleDelete(row)" -->
          <el-button type="text" @click="handleting(row)">停用</el-button>
          <el-button type="text" @click="handleEdittwo(row)">处理</el-button>
          <el-button type="text" @click="handleEditthree(row)">详情</el-button>
        </template>
      </el-table-column>
      <template #empty>
        <el-image
          class="vab-data-empty"
          :src="require('@/assets/empty_images/data_empty.png')"
        />
      </template>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <edit ref="edit" @fetch-data="fetchData" />
    <Deactivate ref="Deactivate" @fetch-data="fetchData" />
    <editting ref="editting" @fetch-data="fetchData" />
    <Editxiangqing ref="Editxiangqing" @fetch-data="fetchData" />
  </div>
</template>

<script>
  import { getList } from '@/api/lingdui'
  import Edit from './components/lingduiedit.vue'
  import Deactivate from './components/tingyong.vue'
  import editting from './component/tingzhi.vue'
  import Editxiangqing from './component/xiangqing.vue'

  export default {
    name: 'UserManagement',
    components: { Edit, Deactivate, editting, Editxiangqing },
    data() {
      return {
        PayTime: '',
        value: '',
        options1: [
          {
            id: '0',
            creClasName: '未审核',
          },
          {
            id: '1',
            creClasName: '待审核',
          },
          {
            id: '2',
            creClasName: '审核通过',
          },
          {
            id: '3',
            creClasName: '审核未通过',
          },
        ], //审核状态
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        queryForm: {
          pageNum: 1,
          pageSize: 10,
          leaderCheck: '',
          keyWord: '', //chaxun
          starTime: '', //开始时间
          endTime: '', //结束时间
        },
      }
    },
    created() {
      this.fetchData()
    },
    methods: {
      setSelectRows(val) {
        this.selectRows = val
      },
      handleEditthree(row) {
        //详情
        if (row.id) {
          this.$refs['Editxiangqing'].showEdit(row)
        } else {
          this.$refs['Editxiangqing'].showEdit()
        }
      },
      rowStyle({ row }) {
        if (row.locked === 1) {
          return {
            background: '#d3d7e0',
            color: '#d3d7e0',
          }
        }
      },
      handleEdit(row) {
        if (row.id) {
          this.$refs['edit'].showEdit(row)
        } else {
          this.$refs['edit'].showEdit()
        }
      },
      handleEdittwo(row) {
        if (row.id) {
          this.$refs['Deactivate'].showEdit(row)
        } else {
          this.$refs['Deactivate'].showEdit()
        }
      },
      handleting(row) {
        if (row.id) {
          this.$refs['editting'].showEdit(row)
        } else {
          this.$refs['editting'].showEdit()
        }
      },
      // handleDelete(row) {
      //   if (row.id) {
      //     this.$baseConfirm('你确定要删除当前项吗', null, async () => {
      //       const { msg } = await doDelete({ ids: row.id })
      //       this.$baseMessage(msg, 'success', 'vab-hey-message-success')
      //       await this.fetchData()
      //     })
      //   } else {
      //     if (this.selectRows.length > 0) {
      //       const ids = this.selectRows.map((item) => item.id).join()
      //       this.$baseConfirm('你确定要删除选中项吗', null, async () => {
      //         const { msg } = await doDelete({ ids })
      //         this.$baseMessage(msg, 'success', 'vab-hey-message-success')
      //         await this.fetchData()
      //       })
      //     } else {
      //       this.$baseMessage('未选中任何行', 'error', 'vab-hey-message-error')
      //     }
      //   }
      // },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      optosall(e) {
        this.queryForm.leaderCheck = e.id
        this.queryForm.pageNum = 1
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        this.fetchData()
      },
      queryData() {
        this.queryForm.pageNum = 1
        this.fetchData()
      },
      //支付时间戳设置
      GetzhifuTime() {
        if (this.PayTime) {
          this.queryForm.starTime = this.PayTime[0]
          this.queryForm.endTime = this.PayTime[1]
          this.queryForm.pageNum = 1
          this.fetchData()
        }
      },

      // async fetchData() {
      //   this.listLoading = true
      //   const {....
      //     data: { list, total },
      //   } = await getList(this.queryForm)
      //   this.list = list
      //   this.total = total
      //   this.listLoading = false
      // },
      async fetchData() {
        this.listLoading = true
        const res = await getList(this.queryForm)
        this.list = res.data.dataList
        this.total = res.data.total
        this.listLoading = false
      },
    },
  }
</script>
<style></style>
